package cn.itcast.bos.mq;

import java.io.UnsupportedEncodingException;

import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.MessageListener;

import org.springframework.stereotype.Service;

import cn.itcast.bos.util.SmsUtils;

/**
 * SMScustomer类
 * 
 * @author 王文杰
 * @version 1.0, 2017-9-12 22:31:50
 */
@Service("smsConsumer")
public class SmsConsumer implements MessageListener{

	@Override
	public void onMessage(Message message) {
		
		MapMessage mapMessage = (MapMessage) message;
		
		// 调用SMS服务发送短信   这就是通过吉信通平台把短信发给注册用户
//		String result;
		try {
//			String result = SmsUtils.sendSmsByHTTP(mapMessage.getString("telephone"), mapMessage.getString("msg"));
		
			// 为了保证代码测试 ,自定义结果 take_delivery
			String result = "000/xxx";
			if(result.startsWith("000")){
				// 说明发送成功
				System.out.println("发送短信成功,手机号:"+mapMessage.getString("telephone")+"验证码:"+mapMessage.getString("msg"));
			}else{
				throw new RuntimeException("短信发送失败,信息码:"+result);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} 

	}

	
}
